var windowName = "userInfo";
apiready = function(){
    onWindowShow(function () {
    })
    onWindowHide(function () {
    })
    console.log("index page is OK");
    var PicUpUserHead = new PicUp()
    var Page = createVM("#Page",{
        //页面数据
        picUserHead:picUserHead,
        form: {
            name: ''
            ,phone: ''
            ,pic:""
            ,picV:""
        }
        ,loading:0
        ,pics:[]
        ,toolsShow:false
    },{
        //页面方法
        "init":function () {
            var userInfo = getLocData("userInfo")
            // console.log(JSON.stringify(userInfo));
            // console.log(typeof userInfo);
            if (userInfo !== "") {
                this.form = userInfo
            }
            getInfo(this);

        }
        ,"submit":function() {
            var _this = this
            this.$refs.form.validate().then((result) => {
                logJson(result)
                if (result){
                    apiPost("/app/user/info",this.form,function (res) {
                        logJson(res)
                        showToast(res.message)
                        setLocData('userInfo',_this.form)
                    })

                }else{
                    showToast("请检查输入")
                }
            });
        },
        selectEditPic:function () {
            var _this = this;
            PicUpUserHead.selectEdit(()=>{_this.toolsShow = true})
                .setCbFunc(function (pics) {
                _this.form.pic = pics[0]
                _this.form.picV = PicUpUserHead.getViewData(pics)[0]
            })
        }
        ,save:function () {
            PicUpUserHead.editSave()
            this.toolsShow = false
        }
        ,reset:PicUpUserHead.editReset
        ,close:function () {
            PicUpUserHead.editClose()
            this.toolsShow = false
        }
    })
    Page.init()
}


function getInfo(_this) {
    apiGet("/app/user/info",{},function (res) {
        logJson(res)
        // showToast(res.message)
        _this.form = res.data
        _this.form.picV = getAssetBaseUrl() + res.data.pic
        setLocData('userInfo',_this.form)
    })
}